package com.github.livebase.log;

import java.lang.reflect.Array;

/**
 * @ClassName ToStringRef
 * @description:
 * @author: biao532
 * @create: 2024-02-18 21:47
 * @Version 1.0
 **/
public class ToStringRef {
    private Object object;
    public ToStringRef(Object obj) {
        this.object = obj;
    }
    protected ToStringRef() {}
    protected void setObject(Object object) {
        this.object = object;
    }

    @Override
    public String toString() {
        if (object.getClass().isArray()) {
            StringBuilder builder = new StringBuilder();
            for (int i = 0, l = Array.getLength(object); i < l; i ++) {
                builder.append(", ");
                builder.append(Array.get(object, i));
            }
            if (builder.length() == 0) {
                builder.append(", ");
            }
            return "L(" + builder.substring(2) + ")";
        }
        return String.valueOf(object);
    }
}
